import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import { sendTicket } from './api/user'
Vue.config.productionTip = false
Vue.prototype.$serverPath="10.177.88.177:8888";
Vue.use(ElementUI);


/**
 * 在创建Vue示例之前就应该验证单点
 */
const params = new URLSearchParams(window.location.search);
const ticket = params.get('ticket');

if(ticket){
  let res = await sendTicket(ticket).then(res => {
    console.log(res)
    if (res.code === 200) {
      console.log(res);
      localStorage.setItem("CRP", res.data.user.username)
      localStorage.setItem("authToken", res.data.token)
      // 金智登录的userId
      localStorage.setItem("userId", res.data.user.id)
    } else {
      // 校验失败， 就清空本地token， 让用户自己登录
      localStorage.removeItem('CRP');
      localStorage.removeItem('authToken')
      localStorage.removeItem('userId')
    }
  }).catch(() => {
    console.log('校验失败')
    //next('/login'); // 处理请求失败的情况
  });

}else{
  console.log('没有ticket')
}



new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
